istio服務無法訪問

前言

今天上班就發現這個情況,istio的服務無法訪問,但同一個叢集的另一個istio卻正常。

正文

看事件錯誤寫的是
Readiness probe failed: HTTP probe failed with statuscode: 503

15.fig-1.jpg

pod 的狀態是running ,但istio-proxy 卻是 containers with unready status

15.fig-2.jpg

根據錯誤訊息都沒找到相符合的資料
ref.
Readiness probe failed: HTTP probe failed with statuscode: 503 #23283

現在看istio-proxy的日誌,上面寫的是
Envoy proxy is NOT ready: config not received from Pilot (is Pilot running?)
這個似乎是原因..

  1. 查看網格的狀況
    istioctl proxy-status

15.fig-3.jpg
所屬的網格LDS寫 Never Ackonwledged
各欄位的意思如下

ref. Pilot

  1. 查看pod錯誤
Envoy proxy is NOT ready: config not received from Pilot (is Pilot running?): cds updates: 1 successful, 0 rejected; lds updates: 0 successful, 1 rejected

我一直以爲關鍵字是查前面的config not received from Pilot(is Pilot running?)
但後來開了工單找了Google工程師,他說重點是後面那句 lds updates: 0 successful, 1 rejected

然後查看 istiod log,可以看到lds為什麼會rejected

warn	ads	ADS:LDS: ACK ERROR router~10.131.1.19~istio-ingressgateway-794bbdb877-np94z.istio-system~istio-system.svc.cluster.local-994 Internal:Error adding/updating listener(s) 0.0.0.0_8443: Invalid path: /etc/istio/ingressgateway-certs/tls.crt

這段在pod剛開始建立時也有出現此錯誤,看起來是https的憑證有問題,
本來佈署gateway的yaml檔像這樣

  apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: istio-ingressgateway-video
  namespace: sex-system
spec:
  selector:
    istio: ingressgateway   # 使用默認的控制器
  servers:
  - port: #加密傳輸
      number: 443
      name: http
      protocol: HTTPS
    tls:
      mode: SIMPLE
      serverCertificate: /etc/istio/ingressgateway-certs/tls.crt #設定憑證路徑
      privateKey: /etc/istio/ingressgateway-certs/tls.key  #設定憑證路徑
    hosts:
      - "*" #該服務對應domain
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
     - "*" #該服務對應domain

憑證路徑是直接指向pod裡面的路徑,

google工程師說 istio v1.6開始gateway的tls已经不支援file mount类的设置了(i.e. privateKey, serverCertificate). 。

所以,要麻自己建立 https的憑證 ,或者是乾脆不要https。
(ref. Secure Gateways)

自己建立憑證的話,
根據上面的網址,產生 crt 跟 key ,然後使用

kubectl create secret tls credential-httpbin -n istio-system --cert=./httpbin.com.crt --key=./httpbin.com.key

建立sercret,最後再yaml內直接使用這個sercret的name

apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: istio-ingressgateway-custom
  namespace: rd7-video
spec:
  selector:
    istio: ingressgateway-private   # 使用默認的控制器
  servers:
  - hosts:
      - httpbin.com
    port:
      name: httpbin
      number: 443
      protocol: HTTPS
    tls:
      credentialName: credential-httpbin
      mode: SIMPLE
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
     - "*" #該服務對應domain

目前看起來是有直接解掉這個問題,
剛剛掛掉的pod,有變回正常的狀態。
但當初兩個pod,一個活着,另一個陣亡,還不知道爲何會這樣。